home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Floppyshop 2
/
Floppyshop - 2.zip
/
Floppyshop - 2.iso
/
art&graf.ix
/
art-0039
/
source
/
dcprtcnv.mod
< prev
next >
Wrap
Text File
|
1997-04-16
|
15KB
|
453 lines
IMPLEMENTATION MODULE DCPrtCnv;
(*----------------------------------------------------------------------*)
(* *)
(* Version 1.00 July 1988 L.G. Miller *)
(* *)
(* The fixed point accuracy is 11 bits ( 1 part in 2048 ) *)
(* *)
(*----------------------------------------------------------------------*)
(* IMPORT Trace; *)
FROM SYSTEM IMPORT ADR, ADDRESS, WORD, BYTE;
FROM DCGlobal IMPORT HiResScreen,
PrinterTypes,
BITSPERWORD;
FROM DCQPicCnv IMPORT QQryHRPixel;
CONST
CFixedPointScale = LONGINT(2048); (* must be power of 2 *)
CFixedPointShift = 11;
TYPE
LONGBITSET = SET OF [ 0 .. 31 ];
VAR PrinterToUse : PrinterTypes;
(* these set up at NewPicture & maintained during conversion *)
InStartX, InStartY,
InEndX, InEndY,
OutNumberOfColumns : INTEGER; (* number of columns to be output *)
PicXScaleFactor,
PicYScaleFactor : INTEGER; (* CFixedPointScale times too big *)
InNextLine : LONGINT; (* Sum of scaled print intervals *)
LastPrintLine,
NextPrintLine : INTEGER;
DirectionIsLandscape : BOOLEAN; (* TRUE ==> x is down the page *)
PROCEDURE QueryPicturePixel( x, y : INTEGER ; (* co-ords *)
VAR pic : HiResScreen ) : BOOLEAN;
VAR groupno, bitno : INTEGER;
addr : ADDRESS;
BEGIN
groupno := x DIV BITSPERWORD;
bitno := x MOD BITSPERWORD;
RETURN ( CARDINAL(bitno) IN pic[y][groupno] );
END QueryPicturePixel;
(*----------------------------------------------------------------------*)
(* Given relative print co-ordinates, calculate the relative picture *)
(* co-ordinates. *)
(* Uses Global Constant CFixedPointScale & Global variables *)
(* PicXScaleFactor & PicYScaleFactor. *)
(*----------------------------------------------------------------------*)
PROCEDURE GetRelPictureCoords( PrintX, PrintY : INTEGER;
ScaleX, ScaleY : INTEGER;
VAR PicX, PicY : INTEGER );
VAR px, py, lx, ly : LONGINT;
BEGIN
px := LONG(PrintX);
py := LONG(PrintY);
PicX := SHORT( ( ( px * ScaleX ) DIV CFixedPointScale ));
PicY := SHORT( ( ( py * ScaleY ) DIV CFixedPointScale ));
END GetRelPictureCoords;
PROCEDURE QueryPrinterToUse() : PrinterTypes;
BEGIN
RETURN PrinterToUse;
END QueryPrinterToUse;
PROCEDURE SetPrinterToUse ( ptype : PrinterTypes );
BEGIN
PrinterToUse := ptype;
END SetPrinterToUse;
PROCEDURE GetScaleFactor ( insize , outsize : INTEGER ) : INTEGER;
VAR li, lo : LONGINT;
BEGIN
li := LONG(insize); lo := LONG(outsize);
RETURN SHORT( ( ( li * CFixedPointScale ) DIV lo ) );
END GetScaleFactor;
(*----------------------------------------------------------------------*)
(* These routines set the global variables for subsequent conversion *)
(*----------------------------------------------------------------------*)
PROCEDURE SetGlobal ( InX, InY : INTEGER; (* range of input *)
PicWidth,
PicHeight,
PrintWidth,
PrintHeight : INTEGER; (* 1 .. width *)
Landscape : BOOLEAN (* true = sideways *)
) ;
VAR s : INTEGER;
ldepth, lnewwidth, lwidth : LONGINT;
BEGIN
InStartX := InX;
InStartY := InY;
InEndX := InX + PicWidth - 1;
InEndY := InY + PicHeight - 1;
DirectionIsLandscape := Landscape;
InNextLine := 0;
NextPrintLine := 0;
IF Landscape THEN
OutNumberOfColumns := PrintHeight;
LastPrintLine := PrintWidth-1;
ELSE
OutNumberOfColumns := PrintWidth;
LastPrintLine := PrintHeight-1;
END;
PicXScaleFactor := GetScaleFactor(PicWidth, PrintWidth);
PicYScaleFactor := GetScaleFactor(PicHeight, PrintHeight);
END SetGlobal;
PROCEDURE GetLandscape8BitSlice( VAR pic : HiResScreen;
VAR buff : ARRAY OF CHAR ) : BOOLEAN;
CONST CNoLines = 8;
VAR picx, picy : INTEGER;
prtx, prty : INTEGER;
disp : INTEGER;
BuffIndex : CARDINAL;
bitno : CARDINAL;
bitslice : LONGBITSET;
chrptr : POINTER TO CHAR; (* cheat time *)
BEGIN
FOR BuffIndex := 0 TO SHORT(HIGH(buff)) DO buff[BuffIndex] := 0C END;
BuffIndex := 0;
(* every output bit is mapped to an input pixel *)
FOR prtx := 0 TO OutNumberOfColumns-1 DO (* y co-ord of picture *)
bitslice := LONGBITSET{};
bitno := 0;
disp := 0; (* number of lines printed this pass *)
prty := NextPrintLine; (* print line *) (* x co-ord of picture *)
REPEAT
GetRelPictureCoords( prty, prtx,
PicXScaleFactor, PicYScaleFactor,
picx, picy );
INC(picx,InStartX);
picy := InEndY - picy;
IF QQryHRPixel( picx, picy, pic ) THEN
INCL(bitslice,bitno);
END;
INC(bitno);
INC(disp);
INC(prty);
UNTIL ( disp >= CNoLines ) OR ( prty > LastPrintLine );
(* put characters in buffer - using a very dirty method *)
IF BuffIndex <= HIGH(buff) THEN
chrptr := ADR(bitslice); (* i know its naughty *)
buff[BuffIndex] := chrptr^; (* top 8 bits *)
INC(BuffIndex);
END;
END; (* for outcol *)
INC(NextPrintLine,CNoLines);
RETURN ( NextPrintLine >= LastPrintLine );
END GetLandscape8BitSlice;
PROCEDURE GetLandscape24BitSlice( VAR pic : HiResScreen;
VAR buff : ARRAY OF CHAR
) : BOOLEAN (* true in no more slices *);
CONST CNoLines = 24;
VAR picx, picy : INTEGER;
prtx, prty : INTEGER;
disp : INTEGER;
BuffIndex : CARDINAL;
bitno : CARDINAL;
bitslice : LONGBITSET;
chrptr : POINTER TO CHAR; (* cheat time *)
BEGIN
FOR BuffIndex := 0 TO SHORT(HIGH(buff)) DO buff[BuffIndex] := 0C END;
BuffIndex := 0;
(* every output bit is mapped to an input pixel *)
FOR prtx := 0 TO OutNumberOfColumns-1 DO (* y co-ord of picture *)
bitslice := LONGBITSET{};
bitno := 0;
disp := 0; (* number of lines printed this pass *)
prty := NextPrintLine; (* print line *) (* x co-ord of picture *)
REPEAT
GetRelPictureCoords( prty, prtx,
PicXScaleFactor, PicYScaleFactor,
picx, picy );
INC(picx,InStartX);
picy := InEndY - picy;
IF QQryHRPixel( picx, picy, pic ) THEN
INCL(bitslice,bitno);
END;
INC(bitno);
INC(disp);
INC(prty);
UNTIL ( disp >= CNoLines ) OR ( prty > LastPrintLine );
(* put characters in buffer - using a very dirty method *)
IF BuffIndex <= HIGH(buff) THEN
chrptr := ADR(bitslice); (* i know its naughty *)
buff[BuffIndex] := chrptr^; (* top 8 bits *)
chrptr := ADDRESS(LONGCARD(chrptr) + LONGCARD(1));
INC(BuffIndex);
buff[BuffIndex] := chrptr^; (* mid 8 bits *)
chrptr := ADDRESS(LONGCARD(chrptr) + LONGCARD(1));
INC(BuffIndex);
buff[BuffIndex] := chrptr^; (* bot 8 bits *)
INC(BuffIndex);
END;
END; (* for outcol *)
INC(NextPrintLine,CNoLines);
RETURN ( NextPrintLine >= LastPrintLine );
END GetLandscape24BitSlice;
PROCEDURE GetPortrait24BitSlice( VAR pic : HiResScreen;
VAR buff : ARRAY OF CHAR ) : BOOLEAN;
CONST CNoLines = 24;
VAR picx, picy : INTEGER;
prtx, prty : INTEGER;
disp : INTEGER;
BuffIndex : CARDINAL;
bitno : CARDINAL;
bitslice : LONGBITSET;
chrptr : POINTER TO CHAR; (* cheat time *)
BEGIN
FOR BuffIndex := 0 TO SHORT(HIGH(buff)) DO buff[BuffIndex] := 0C END;
BuffIndex := 0;
(* every output bit is mapped to an input pixel *)
FOR prtx := 0 TO OutNumberOfColumns-1 DO
bitslice := LONGBITSET{};
bitno := 0;
disp := 0; (* number of lines printed this pass *)
prty := NextPrintLine; (* print line *)
REPEAT
GetRelPictureCoords( prtx, prty,
PicXScaleFactor, PicYScaleFactor,
picx, picy );
INC(picx,InStartX);
INC(picy,InStartY);
IF QQryHRPixel( picx, picy, pic ) THEN
INCL(bitslice,bitno);
END;
INC(bitno);
INC(disp);
INC(prty);
UNTIL ( disp >= CNoLines ) OR ( prty > LastPrintLine );
(* put characters in buffer - using a very dirty method *)
IF BuffIndex <= HIGH(buff) THEN
chrptr := ADR(bitslice); (* i know its naughty *)
buff[BuffIndex] := chrptr^; (* top 8 bits *)
chrptr := ADDRESS(LONGCARD(chrptr)+LONGCARD(1));
INC(BuffIndex);
buff[BuffIndex] := chrptr^; (* mid 8 bits *)
chrptr := ADDRESS(LONGCARD(chrptr)+LONGCARD(1));
INC(BuffIndex);
buff[BuffIndex] := chrptr^; (* bot 8 bits *)
INC(BuffIndex);
END;
END; (* for outcol *)
INC(NextPrintLine,CNoLines);
RETURN ( NextPrintLine >= LastPrintLine );
END GetPortrait24BitSlice;
PROCEDURE GetPortrait8BitSlice( VAR pic : HiResScreen;
VAR buff : ARRAY OF CHAR ) : BOOLEAN;
CONST CNoLines = 8;
VAR picx, picy : INTEGER;
prtx, prty : INTEGER;
disp : INTEGER;
BuffIndex : CARDINAL;
bitno : CARDINAL;
bitslice : LONGBITSET;
chrptr : POINTER TO CHAR; (* cheat time *)
BEGIN
FOR BuffIndex := 0 TO SHORT(HIGH(buff)) DO buff[BuffIndex] := 0C END;
BuffIndex := 0;
(* every output bit is mapped to an input pixel *)
FOR prtx := 0 TO OutNumberOfColumns-1 DO
bitslice := LONGBITSET{};
bitno := 0;
disp := 0; (* number of lines printed this pass *)
prty := NextPrintLine; (* print line *)
REPEAT
GetRelPictureCoords( prtx, prty,
PicXScaleFactor, PicYScaleFactor,
picx, picy );
INC(picx,InStartX);
INC(picy,InStartY);
IF QQryHRPixel( picx, picy, pic ) THEN
INCL(bitslice,bitno);
END;
INC(bitno);
INC(disp);
INC(prty);
UNTIL ( disp >= CNoLines ) OR ( prty > LastPrintLine );
(* put characters in buffer - using a very dirty method *)
IF BuffIndex <= HIGH(buff) THEN
chrptr := ADR(bitslice); (* i know its naughty *)
buff[BuffIndex] := chrptr^; (* bot 8 bits *)
INC(BuffIndex);
END;
END; (* for outcol *)
INC(NextPrintLine,CNoLines);
RETURN ( NextPrintLine >= LastPrintLine );
END GetPortrait8BitSlice;
PROCEDURE PrtCnv8BitSlice ( NewPicture : BOOLEAN; (* TRUE is restart *)
VAR last : BOOLEAN; (* TRUE if end *)
VAR picture : HiResScreen;
InX, InY,
PicWidth,
PicHeight,
PrintWidth,
PrintHeight: INTEGER; (* *)
Landscape : BOOLEAN; (* true = sideways *)
VAR buffer : ARRAY OF CHAR (* out *)
);
BEGIN
IF NewPicture THEN
SetGlobal( InX, InY, PicWidth, PicHeight,
PrintWidth, PrintHeight,
Landscape );
END;
IF DirectionIsLandscape THEN
last := GetLandscape8BitSlice( picture, buffer );
ELSE
last := GetPortrait8BitSlice( picture, buffer );
END;
END PrtCnv8BitSlice;
PROCEDURE PrtCnv24BitSlice ( NewPicture : BOOLEAN; (* TRUE is restart *)
VAR last : BOOLEAN; (* TRUE if end *)
VAR picture : HiResScreen;
InX, InY,
PicWidth,
PicHeight,
PrintWidth,
PrintHeight: INTEGER; (* *)
Landscape : BOOLEAN; (* true = sideways*)
VAR buffer : ARRAY OF CHAR (* out *)
);
BEGIN
IF NewPicture THEN
SetGlobal( InX, InY, PicWidth, PicHeight,
PrintWidth, PrintHeight,
Landscape );
END; (* if *)
IF DirectionIsLandscape THEN
last := GetLandscape24BitSlice( picture, buffer );
ELSE
last := GetPortrait24BitSlice( picture, buffer );
END;
END PrtCnv24BitSlice;
END DCPrtCnv.